<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>获取和设置元素属性</title>
</head>

<body>
    <input class="类名" type="text" name="xxname" id="xxid" value="学习笔记" abcc="自定义属性"/>
    <script>
        document.write('<p>获取和设置元素属性</p>')
        document.write('获取标签属性：<br>1、要先获取标签元素；<br>2、再根据标签元素获取属性。<br><br>')
        var xxbj = document.getElementById('xxid');
        document.write(document.getElementById('xxid').value,'<br>')
        document.write(xxbj.id,'<br>')
        document.write(xxbj.type,'<br>')
        document.write(xxbj.value,'<br>')

        document.write('<p style="color:red">注：自定义属性不能通过这种方法获取；如果要获取 class属性，则使用 className来获取。</p><br>')
        var xxbj2 = document.getElementById('xxid').className;
        document.write(xxbj2,'<br>')
    </script>
</body>

</html>